package com.jzz.eletuanbackend.controller;

import com.jzz.eletuanbackend.service.CustomerService;
import com.jzz.eletuanbackend.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping("/shops")
    public Msg allShops() {
        return customerService.allShops();
    }

    @RequestMapping("/shop/{id}")
    public Msg shop(@PathVariable("id") Long id) {
        return customerService.shop(id);
    }

    @PostMapping("/order/pay")
    public Msg pay(@RequestParam("user_id") Long userId, @RequestParam("orderId") Long orderId) {
        return customerService.pay(userId, orderId);
    }

    @PostMapping("/order/submit")
    public Msg submitOrder(@RequestParam("user_id") Long userId, @RequestParam("commodities") String commodities,
                           @RequestParam("receiveInfo") String receiveInfo) {
        return customerService.submitOrder(userId, commodities, receiveInfo);
    }

    @PostMapping("/order/cancel")
    public Msg cancelOrder(@RequestParam("user_id") Long userId, @RequestParam("orderId") Long id) {
        return customerService.cancelOrder(userId, id);
    }

    @RequestMapping("/order/pos")
    public Msg getPosition(@RequestParam("user_id") Long userId, @RequestParam("orderId") Long orderId) {
        return customerService.getPosition(userId, orderId);
    }

    @RequestMapping("/order/get")
    public Msg getOrder(@RequestParam("orderId") Long orderId) {
        return customerService.getOrder(orderId);
    }

    @RequestMapping("/order/all")
    public Msg getAllOrders(@RequestParam("user_id") Long userId) {
        return customerService.getAllOrders(userId);
    }

    @PostMapping("/order/comment")
    public Msg commentOrder(@RequestParam("orderId") Long orderId, @RequestParam("shopComment") String shopComment,
                            @RequestParam("delivererComment") String delivererComment,
                            @RequestParam("shopStar") Integer shopStar, @RequestParam("deliverStar") Integer deliverStar) {
        return customerService.commentOrder(orderId, shopComment, delivererComment, shopStar, deliverStar);
    }

    @PostMapping("/receiveInfo/edit")
    public Msg editReceiveInfo(@RequestParam("user_id") Long userId,
                               @RequestParam("info") String info) {
        return customerService.editReceiveInfo(userId, info);
    }

    @PostMapping("/info")
    public Msg info(@RequestParam("user_id") Long userId) {
        return customerService.info(userId);
    }

}
